package com.ykl.cas.utils;

import org.springframework.jdbc.datasource.DriverManagerDataSource;

import java.io.IOException;
import java.util.Properties;

public class DataSourceUtils {
  private static Properties dbProperties = new Properties();
  public static String driverClassName;
  public static String url;
  public static String username;
  public static String password;

  static {
    try {
      dbProperties.load(DataSourceUtils.class.getClassLoader().getResourceAsStream("db.properties"));
    } catch (IOException e) {
      e.printStackTrace();
    }
    driverClassName=dbProperties.getProperty("driverClassName");
    url=dbProperties.getProperty("jdbcUrl");
    username=dbProperties.getProperty("username");
    password=dbProperties.getProperty("password");

  }
  public static DriverManagerDataSource getDataSource(){
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(driverClassName);
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    return dataSource;
  }
}
